package com.example.black.myapplication.filtercolorrgb;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.example.black.myapplication.R;

public class MaskFilterView2 extends View {

    private RectF rectF;
    private Paint paint;
    private BlurMaskFilter blurMaskFilter;
    private Bitmap bitmap;

    public MaskFilterView2(Context context) {
        super(context);
        initConfig();
    }

    public MaskFilterView2(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initConfig();
    }

    public MaskFilterView2(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initConfig();
    }

    private void initConfig() {
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        //关闭硬件加速才有效果 ？？？
        setLayerType(View.LAYER_TYPE_SOFTWARE,paint);
       // blurMaskFilter = new BlurMaskFilter(65, BlurMaskFilter.Blur.OUTER); 似乎可以实现彩色阴影效果
        blurMaskFilter = new BlurMaskFilter(95, BlurMaskFilter.Blur.NORMAL);//OUTER 和 SOLID 区别
        bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon3);
        rectF = new RectF(100, 100, bitmap.getWidth(), bitmap.getHeight());
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(getResources().getColor(R.color.colorPrimaryBlueDark));
        paint.setMaskFilter(blurMaskFilter);
        canvas.drawBitmap(bitmap,100,100,paint);
    }
}
